/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.fxml.FXML
 *  javafx.fxml.FXMLLoader
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Toggle
 *  javafx.scene.control.ToggleButton
 *  javafx.scene.control.ToggleGroup
 *  javafx.scene.layout.GridPane
 */
package com.gys.common.plugIn.dateTimePicker;

import com.gys.common.plugIn.dateTimePicker.DateTimePickerPopup;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;

public class HoursPicker
extends GridPane
implements Initializable {
    private static final int NUM_BUTTONS = 12;
    private final List<ToggleButton> buttonList = new ArrayList<ToggleButton>(12);
    private final DateTimePickerPopup parentContainer;
    @FXML
    private ToggleGroup hoursToggleGroup;
    @FXML
    private ToggleButton zeroButton;
    @FXML
    private ToggleButton oneButton;
    @FXML
    private ToggleButton twoButton;
    @FXML
    private ToggleButton threeButton;
    @FXML
    private ToggleButton fourButton;
    @FXML
    private ToggleButton fiveButton;
    @FXML
    private ToggleButton sixButton;
    @FXML
    private ToggleButton sevenButton;
    @FXML
    private ToggleButton eightButton;
    @FXML
    private ToggleButton nineButton;
    @FXML
    private ToggleButton tenButton;
    @FXML
    private ToggleButton elevenButton;
    @FXML
    private ToggleButton amPmButton;

    HoursPicker(DateTimePickerPopup parentContainer) {
        this.parentContainer = parentContainer;
        URL url = HoursPicker.class.getClass().getResource("/fxml/dateTimePicker/HoursPicker.fxml");
        FXMLLoader fxmlLoader = new FXMLLoader();
        try {
            fxmlLoader = new FXMLLoader(url);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        }
        catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    public void initialize(URL location, ResourceBundle resources) {
        this.buttonList.add(this.zeroButton);
        this.buttonList.add(this.oneButton);
        this.buttonList.add(this.twoButton);
        this.buttonList.add(this.threeButton);
        this.buttonList.add(this.fourButton);
        this.buttonList.add(this.fiveButton);
        this.buttonList.add(this.sixButton);
        this.buttonList.add(this.sevenButton);
        this.buttonList.add(this.eightButton);
        this.buttonList.add(this.nineButton);
        this.buttonList.add(this.tenButton);
        this.buttonList.add(this.elevenButton);
        this.amPmButton.prefHeightProperty().bind((ObservableValue)this.zeroButton.heightProperty().multiply(3).add(this.getHgap() * 2.0));
        this.amPmButton.prefWidthProperty().set(50.0);
        this.amPmButton.selectedProperty().addListener((ChangeListener)new ChangeListener<Boolean>(){

            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                int offset = 0;
                if (newValue.booleanValue()) {
                    HoursPicker.this.amPmButton.setText("PM");
                    offset = 12;
                } else {
                    HoursPicker.this.amPmButton.setText("AM");
                }
                for (int i = 0; i < 12; ++i) {
                    ((ToggleButton)HoursPicker.this.buttonList.get(i)).setText(String.format("%02d", i + offset));
                }
            }
        });
        int hour = this.parentContainer.getHour();
        int offset = 0;
        if (hour > 11) {
            this.amPmButton.setSelected(true);
            offset = -12;
        }
        this.hoursToggleGroup.selectToggle((Toggle)this.buttonList.get(hour + offset));
        this.hoursToggleGroup.selectedToggleProperty().addListener((ChangeListener)new ChangeListener<Toggle>(){

            public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
                if (newValue == null) {
                    HoursPicker.this.hoursToggleGroup.selectToggle(oldValue);
                } else {
                    HoursPicker.this.parentContainer.restoreTimePanel();
                }
            }
        });
    }

    int getHour() {
        int hour = this.buttonList.indexOf(this.hoursToggleGroup.getSelectedToggle());
        if (this.amPmButton.isSelected()) {
            hour += 12;
        }
        return hour;
    }
}

